package org.liuh.designs.spider;

import com.alibaba.fastjson.JSON;
import org.liuh.designs.spider.utils.NioFileReader;
import org.liuh.designs.spider.utils.ReaderListener;

import java.util.List;

/**
 * @ClassName: ReadTxt
 * @Description:
 * @Author: liuh
 * @Date: 2020/10/13 11:07
 * @Version: 1.0
 */
public class ReadTxt {

    /**
     * @Description: NioFileReader读取.. 相对于程序同步读取.. 文件异步读.
     * @Author: liuh
     * @Date: 2020/10/13
     */
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        String fileBykey = TownSpiderMain.RdsKeyFileRelationEnum.getFileBykey(AreaConstant.RDS_COUNTY_KEY);
        ReaderListener readerListener = new ReaderListener() {
            @Override
            public void output(List<String> lineList) throws Exception {
                for (String s : lineList) {
                    sb.append(s);
                }
            }
        };
        readerListener.setReadColNum(100000);
        NioFileReader reader = new NioFileReader(readerListener, "utf-8");
        try {
            reader.readFileByLine(fileBykey);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println(sb.toString());
        System.out.println(String.format("主程序暂停, threadName: %s", Thread.currentThread().getName()));
    }

}
